package cn.com.clearbus.utils;

import cn.com.clearbus.entity.weChat.node.Node;
import cn.com.clearbus.entity.weChat.node.UrlNode;

public class UrlUtil {

    private static String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect";

    public static String buildSimpleUrl(Node e){
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("<a href = '").append(((UrlNode) e).getUrl()).append("'>")
                .append(e.toString()).append("</a>");
        System.out.println("url为:"+stringBuilder.toString());
        return stringBuilder.toString();
    }

    public static String buildBaseAuthorizeUrl(Node e, String appId){
        String result = url.replace("APPID", appId).replace("REDIRECT_URI", ((UrlNode) e).getUrl())
                .replace("SCOPE", "snsapi_base").replace("STATE", "123");
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("<a href = '").append(result).append("'>")
                .append(e.toString()).append("</a>");
        System.out.println("url result为:"+stringBuilder.toString());
        return stringBuilder.toString();
    }
}
